//
//  HyTextF.swift
//  OneMeeting
//
//  Created by zhangheng on 2019/8/16.
//  Copyright © 2019 www.zhangheng.com. All rights reserved.
//


import Cocoa

typealias TouchupBlock = (String,Int)->Void
class HyTextF: NSTextField {
    var href: String?
    var touchBlock: TouchupBlock?
    
    public func addTouchBlock(block:@escaping TouchupBlock){
        touchBlock = block
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override func mouseDown(with theEvent: NSEvent) {
        if let _ = touchBlock {
            self.touchBlock!(self.stringValue,self.stringValue.count)
        }
        if let _ = href {
            NSWorkspace.shared.open(NSURL(string: self.href!)! as URL)
        }
        
    }
 
}

